//
//  PersonalInforViewController.m
//  gdemm
//
//  Created by wu yong on 16/9/28.
//  Copyright © 2016年 Goldencis. All rights reserved.
//

#import "PersonalInforViewController.h"
#import "UserDefaultsUtil.h"
#import "Utils.h"
#import "gdsm3.h"
#import "HttpUtil.h"
#import "ApiSupport.h"
#import "ToastManager.h"
#import "MBProgressHUD.h"
#import "Masonry.h"
@interface PersonalInforViewController ()
@property(nonatomic,strong)UITextField * realNameTextFiled;
@property(nonatomic,strong)UITextField * oldPwdTextFiled;
@property(nonatomic,strong)UITextField * newpwdTextFiled;
@property(nonatomic,assign)BOOL isSecureText;
@end

@implementation PersonalInforViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        if ([DeviceTypeJudge isPadDeviceType]) {
            button.frame = CGRectMake(0, 0, 20, 20);
        }else{
            button.frame = CGRectMake(0, 0, 16, 16);
        }
        
        [button setImage:[[Utils getImageByDevce:@"navigationBar_back"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(leftButtonPopHandler) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithCustomView:button];
        self.navigationItem.leftBarButtonItem = leftButton;
        self.navigationItem.title = NSLocalizedString(@"str_user_information",  @"个人信息");
    }
    return self;
}
-(void)viewDidLoad {
    [super viewDidLoad];
    self.isSecureText = NO;
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [Utils colorWithKey:@"registerNavBarBgColor"];
    self.view.backgroundColor = [Utils UIColorFromHex:0Xf5f6f8];
    [self setUpView];
}

-(void)setUpView{
    if ([DeviceTypeJudge isPadDeviceType]){
        [self setupIpadView];
    }else{
        [self setupIphoneView];
    }
}

-(void)setupIpadView{

    //用户名
    UIView * userView = [[UIView alloc]init];
    userView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:userView];
    
    UILabel * userNameLabel = [[UILabel alloc]init];
    userNameLabel.text = NSLocalizedString(@"str_user_name", @"用户名");
    userNameLabel.textColor = [Utils UIColorFromHex:0X323232];
    userNameLabel.font = [UIFont systemFontOfSize:18];
    [userView addSubview:userNameLabel];
    UILabel * nameLabel = [[UILabel alloc]init];
    nameLabel.text = [[UserDefaultsUtil shareInstance]getString:LC_USERNAME];
    nameLabel.textColor = [Utils UIColorFromHex:0Xa6a6a6];
    nameLabel.font = [UIFont systemFontOfSize:18];
    [userView addSubview:nameLabel];
    
    [userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(self.view.top).offset(40);
        make.height.mas_equalTo(80);
    }];
    [userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userView.left).offset(13);
        make.centerY.mas_equalTo(userView);
        //        make.width.mas_equalTo(100);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userNameLabel.mas_right).offset(60);
        make.centerY.mas_equalTo(userView);
    }];
    //修改信息
    UIView *updateInfoView = [[UIView alloc]init];
    updateInfoView.backgroundColor = [Utils UIColorFromHex:0XF5F6F8];
    [self.view addSubview:updateInfoView];
    UILabel *updateInfoLabel = [[UILabel alloc]init];
    updateInfoLabel.text = @"修改信息";
    updateInfoLabel.font = [UIFont systemFontOfSize:16];
    updateInfoLabel.textColor = [Utils UIColorFromHex:0XBFBFBF];
    [updateInfoView addSubview:updateInfoLabel];
    [updateInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(userView.mas_bottom);
        make.height.mas_equalTo(78);
    }];
    [updateInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(updateInfoView.mas_left).offset(16);
        make.bottom.mas_equalTo(updateInfoView.mas_bottom).offset(-12);
    }];
    
    //真实姓名
    UIView * realNameView = [[UIView alloc]init];
    realNameView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:realNameView];
    UITextField * realNameTextFiled = [[UITextField alloc]init];
    self.realNameTextFiled = realNameTextFiled;
    realNameTextFiled.leftViewMode = UITextFieldViewModeAlways;
    realNameTextFiled.attributedPlaceholder = [[NSAttributedString alloc]initWithString:[[UserDefaultsUtil shareInstance]getString:LC_TRUENAME] attributes:@{NSForegroundColorAttributeName:[Utils UIColorFromHex:0X323232],NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    [realNameView addSubview:realNameTextFiled];
    UILabel * realNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 18)];
    realNameLabel.text = NSLocalizedString(@"str_true_name", @"真实姓名");
    realNameLabel.textColor = [Utils UIColorFromHex:0X323232];
    realNameLabel.font = [UIFont systemFontOfSize:18];
    realNameTextFiled.leftView = realNameLabel;
    [realNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(updateInfoView.mas_bottom);
        make.height.mas_equalTo(80);
    }];
    [realNameTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(realNameView.mas_left).offset(13);
        make.right.mas_equalTo(realNameView.mas_right);
        make.centerY.mas_equalTo(realNameView);
        make.height.mas_equalTo(18);
    }];
    //修改密码
    UIView *updatePwdView = [[UIView alloc]init];
    updatePwdView.backgroundColor = [Utils UIColorFromHex:0Xf5f6f8];
    [self.view addSubview:updatePwdView];
    UILabel *updatePwdLabel = [[UILabel alloc]init];
    updatePwdLabel.text = @"修改密码（不修改请留空）";
    updatePwdLabel.font = [UIFont systemFontOfSize:16];
    updatePwdLabel.textColor = [Utils UIColorFromHex:0Xbfbfbf];
    [updatePwdView addSubview:updatePwdLabel];
    UIButton * secureBtn = [[UIButton alloc]init];
    [secureBtn setBackgroundImage:[UIImage imageNamed:@"logon_icon_08"] forState:UIControlStateNormal];
    [secureBtn addTarget:self action:@selector(secureBtn:) forControlEvents:UIControlEventTouchUpInside];
    [updatePwdView addSubview:secureBtn];
    
    [updatePwdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(realNameView.mas_bottom);
        make.height.mas_equalTo(78);
    }];
    [updatePwdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(updatePwdView.mas_left).offset(16);
        make.bottom.mas_equalTo(updatePwdView.mas_bottom).offset(-12);
    }];
    [secureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(updatePwdView);
        make.right.mas_equalTo(updatePwdView.bottom).offset(-10);
        make.width.mas_equalTo(32);
        make.height.mas_equalTo(20);
    }];
    //密码
    UIView * passwordView = [[UIView alloc]init];
    passwordView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:passwordView];
    UITextField * oldPwdTextFiled = [[UITextField alloc]init];
    self.oldPwdTextFiled = oldPwdTextFiled;
    oldPwdTextFiled.leftViewMode = UITextFieldViewModeAlways;
    oldPwdTextFiled.secureTextEntry = YES;
    oldPwdTextFiled.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"" attributes:@{NSForegroundColorAttributeName:[Utils UIColorFromHex:0X323232],NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    [passwordView addSubview:oldPwdTextFiled];
    UILabel * oldPwdLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 18)];
    oldPwdLabel.text = NSLocalizedString(@"str_oldPwd", @"原密码");
    oldPwdLabel.textColor = [Utils UIColorFromHex:0X323232];
    oldPwdLabel.font = [UIFont systemFontOfSize:18];
    oldPwdTextFiled.leftView = oldPwdLabel;
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = [Utils UIColorFromHex:0XE6E6E6];
    [passwordView addSubview:lineView];
    
    UITextField * newPwdTextFiled = [[UITextField alloc]init];
    newPwdTextFiled.secureTextEntry = YES;
    self.newpwdTextFiled = newPwdTextFiled;
    newPwdTextFiled.leftViewMode = UITextFieldViewModeAlways;
    newPwdTextFiled.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"" attributes:@{NSForegroundColorAttributeName:[Utils UIColorFromHex:0X323232],NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    [passwordView addSubview:newPwdTextFiled];
    UILabel * newPwdLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 18)];
    newPwdLabel.text = NSLocalizedString(@"str_newPwd", @"新密码");
    newPwdLabel.textColor = [Utils UIColorFromHex:0X323232];
    newPwdLabel.font = [UIFont systemFontOfSize:18];
    newPwdTextFiled.leftView = newPwdLabel;
    
    [passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(updatePwdView.mas_bottom);
        make.height.mas_equalTo(160);
    }];
    [oldPwdTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(realNameView.mas_left).offset(13);
        make.right.mas_equalTo(realNameView.mas_right);
        make.top.mas_equalTo(passwordView.mas_top).offset(30);
        make.height.mas_equalTo(18);
    }];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(passwordView.mas_left).offset(13);
        make.right.mas_equalTo(passwordView.mas_right).offset(-13);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(oldPwdTextFiled.mas_bottom).offset(29);
    }];
    [newPwdTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(realNameView.mas_left).offset(13);
        make.right.mas_equalTo(realNameView.mas_right);
        make.top.mas_equalTo(lineView.mas_bottom).offset(30);
        make.height.mas_equalTo(18);
    }];
    //确定按钮
    UIButton * confirmBtn = [[UIButton alloc]init];
    confirmBtn.layer.cornerRadius = 5;
    [confirmBtn setTitle:NSLocalizedString(@"str_ok", @"确定") forState:UIControlStateNormal];
    [confirmBtn setBackgroundColor:[Utils colorWithKey:@"registerNavBarBgColor"]];
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:20];
    confirmBtn.tintColor = [Utils UIColorFromHex:0Xffffff];
    [confirmBtn addTarget:self action:@selector(confirmhandler:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmBtn];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(456);
        make.height.mas_equalTo(48);
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(passwordView.mas_bottom).offset(176);
    }];
    
}
-(void)setupIphoneView{
    //用户名
    UIView * userView = [[UIView alloc]init];
    userView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:userView];
    
    UILabel * userNameLabel = [[UILabel alloc]init];
    userNameLabel.text = NSLocalizedString(@"str_user_name", @"用户名");
    userNameLabel.textColor = [Utils UIColorFromHex:0X323232];
    userNameLabel.font = [UIFont systemFontOfSize:15];
    [userView addSubview:userNameLabel];
    UILabel * nameLabel = [[UILabel alloc]init];
    nameLabel.text = [[UserDefaultsUtil shareInstance]getString:LC_USERNAME];
    nameLabel.textColor = [Utils UIColorFromHex:0Xa6a6a6];
    nameLabel.font = [UIFont systemFontOfSize:15];
    [userView addSubview:nameLabel];
    
    [userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(self.view.top).offset(30*KHeightScale);
        make.height.mas_equalTo(50*KHeightScale);
    }];
    [userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userView.left).offset(10);
        make.centerY.mas_equalTo(userView);
        make.width.mas_equalTo(80*KWidthScale);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userNameLabel.mas_right)
        ;
        make.centerY.mas_equalTo(userView);
    }];
    //修改信息
    UIView *updateInfoView = [[UIView alloc]init];
    updateInfoView.backgroundColor = [Utils UIColorFromHex:0XF5F6F8];
    [self.view addSubview:updateInfoView];
    UILabel *updateInfoLabel = [[UILabel alloc]init];
    updateInfoLabel.text = @"修改信息";
    updateInfoLabel.font = [UIFont systemFontOfSize:14];
    updateInfoLabel.textColor = [Utils UIColorFromHex:0XBFBFBF];
    [updateInfoView addSubview:updateInfoLabel];
    [updateInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(userView.mas_bottom);
        make.height.mas_equalTo(50*KHeightScale);
    }];
    [updateInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(updateInfoView.mas_left).offset(10);
        make.bottom.mas_equalTo(updateInfoView.mas_bottom).offset(-10);
    }];
    
    //真实姓名
    UIView * realNameView = [[UIView alloc]init];
    realNameView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:realNameView];
    UITextField * realNameTextFiled = [[UITextField alloc]init];
    self.realNameTextFiled = realNameTextFiled;
    realNameTextFiled.leftViewMode = UITextFieldViewModeAlways;
    realNameTextFiled.attributedPlaceholder = [[NSAttributedString alloc]initWithString:[[UserDefaultsUtil shareInstance]getString:LC_TRUENAME] attributes:@{NSForegroundColorAttributeName:[Utils UIColorFromHex:0X323232],NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    [realNameView addSubview:realNameTextFiled];
    UILabel * realNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80*KWidthScale, 18)];
    realNameLabel.text = NSLocalizedString(@"str_true_name", @"真实姓名");
    realNameLabel.textColor = [Utils UIColorFromHex:0X323232];
    realNameLabel.font = [UIFont systemFontOfSize:15];
    realNameTextFiled.leftView = realNameLabel;
    [realNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(updateInfoView.mas_bottom);
        make.height.mas_equalTo(50*KHeightScale);
    }];
    [realNameTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(realNameView.mas_left).offset(10);
        make.right.mas_equalTo(realNameView.mas_right);
        make.centerY.mas_equalTo(realNameView);
        make.height.mas_equalTo(18);
    }];
    //修改密码
    UIView *updatePwdView = [[UIView alloc]init];
    updatePwdView.backgroundColor = [Utils UIColorFromHex:0Xf5f6f8];
    [self.view addSubview:updatePwdView];
    UILabel *updatePwdLabel = [[UILabel alloc]init];
    updatePwdLabel.text = @"修改密码（不修改请留空）";
    updatePwdLabel.font = [UIFont systemFontOfSize:14];
    updatePwdLabel.textColor = [Utils UIColorFromHex:0Xbfbfbf];
    [updatePwdView addSubview:updatePwdLabel];
    UIButton * secureBtn = [[UIButton alloc]init];
    [secureBtn setBackgroundImage:[Utils getImageByDevce:@"logon_icon_08"] forState:UIControlStateNormal];
    [secureBtn addTarget:self action:@selector(secureBtn:) forControlEvents:UIControlEventTouchUpInside];
    [updatePwdView addSubview:secureBtn];
    
    [updatePwdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(realNameView.mas_bottom);
        make.height.mas_equalTo(50*KHeightScale);
    }];
    [updatePwdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(updatePwdView.mas_left).offset(10);
        make.bottom.mas_equalTo(updatePwdView.mas_bottom).offset(-12);
    }];
    [secureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       make.bottom.mas_equalTo(updatePwdView.mas_bottom).offset(-10);
        make.right.mas_equalTo(updatePwdView.bottom).offset(-10);
        make.width.mas_equalTo(18);
        make.height.mas_equalTo(18);
    }];
    //密码
    UIView * passwordView = [[UIView alloc]init];
    passwordView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:passwordView];
    UITextField * oldPwdTextFiled = [[UITextField alloc]init];
    self.oldPwdTextFiled = oldPwdTextFiled;
    oldPwdTextFiled.leftViewMode = UITextFieldViewModeAlways;
    oldPwdTextFiled.secureTextEntry = YES;
    oldPwdTextFiled.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"" attributes:@{NSForegroundColorAttributeName:[Utils UIColorFromHex:0X323232],NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    [passwordView addSubview:oldPwdTextFiled];
    UILabel * oldPwdLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80*KWidthScale, 18)];
    oldPwdLabel.text = NSLocalizedString(@"str_oldPwd", @"原密码");
    oldPwdLabel.textColor = [Utils UIColorFromHex:0X323232];
    oldPwdLabel.font = [UIFont systemFontOfSize:15];
    oldPwdTextFiled.leftView = oldPwdLabel;
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = [Utils UIColorFromHex:0XE6E6E6];
    [passwordView addSubview:lineView];
    
    UITextField * newPwdTextFiled = [[UITextField alloc]init];
    newPwdTextFiled.secureTextEntry = YES;
    self.newpwdTextFiled = newPwdTextFiled;
    newPwdTextFiled.leftViewMode = UITextFieldViewModeAlways;
    newPwdTextFiled.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"" attributes:@{NSForegroundColorAttributeName:[Utils UIColorFromHex:0X323232],NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    [passwordView addSubview:newPwdTextFiled];
    UILabel * newPwdLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80*KWidthScale, 18)];
    newPwdLabel.text = NSLocalizedString(@"str_newPwd", @"新密码");
    newPwdLabel.textColor = [Utils UIColorFromHex:0X323232];
    newPwdLabel.font = [UIFont systemFontOfSize:15];
    newPwdTextFiled.leftView = newPwdLabel;
    
    [passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(updatePwdView.mas_bottom);
        make.height.mas_equalTo(100*KHeightScale);
    }];
    [oldPwdTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(realNameView.mas_left).offset(10);
        make.right.mas_equalTo(realNameView.mas_right);
        make.top.mas_equalTo(passwordView.mas_top).offset(12);
        make.height.mas_equalTo(18);
    }];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(passwordView.mas_left).offset(10);
        make.right.mas_equalTo(passwordView.mas_right).offset(-10);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(passwordView.mas_top).offset(50);
    }];
    [newPwdTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(realNameView.mas_left).offset(10);
        make.right.mas_equalTo(realNameView.mas_right);
        make.top.mas_equalTo(lineView.mas_bottom).offset(12);
        make.height.mas_equalTo(18);
    }];
    //确定按钮
    UIButton * confirmBtn = [[UIButton alloc]init];
    confirmBtn.layer.cornerRadius = 5;
    [confirmBtn setTitle:NSLocalizedString(@"str_ok", @"确定") forState:UIControlStateNormal];
    [confirmBtn setBackgroundColor:[Utils colorWithKey:@"registerNavBarBgColor"]];
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    confirmBtn.tintColor = [Utils UIColorFromHex:0Xffffff];
    [confirmBtn addTarget:self action:@selector(confirmhandler:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmBtn];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(46*KWidthScale);
        make.height.mas_equalTo(36*KHeightScale);
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(passwordView.mas_bottom).offset(81*KHeightScale);
    }];
}


-(void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.hidden  = YES;
    [super viewWillDisappear:animated];
}
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden  = NO;
    [super viewWillAppear:animated];
}
-(void)leftButtonPopHandler{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)confirmhandler:(UIButton *)sender{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[[UserDefaultsUtil shareInstance]getString:LC_USERGUID] forKey:@"userGUID"];
    if (![self.realNameTextFiled.text isEqualToString:@""]) {
        [dict setValue:self.realNameTextFiled.text forKey:@"trueName"];
    }
    if (![self.oldPwdTextFiled.text isEqualToString:@""]) {
        const char *oldStr = [self.oldPwdTextFiled.text UTF8String];
        long oldLen = strlen(oldStr);
        unsigned const char old_out_bf[65];
        sm3_buffer((void *)oldStr,(int)oldLen,(void *)old_out_bf,32);
        [dict setValue:[NSString stringWithUTF8String:(void *)old_out_bf] forKey:@"oldPwd"];
        
    }
    if (![self.newpwdTextFiled.text isEqualToString:@""]) {
        const char *neStr = [self.newpwdTextFiled.text UTF8String];
        long neLen = strlen(neStr);
        unsigned const char ne_out_bf[65];
        sm3_buffer((void *)neStr,(int)neLen,(void *)ne_out_bf,32);
        [dict setValue:[NSString stringWithUTF8String:(void *)ne_out_bf] forKey:@"newPwd"];
        
        
    }
    
    NSString *s = [HttpUtil buildUrl:[ApiSupport getChangeUserInfoUrl] WithParams:dict];
    NSURL *url = [NSURL URLWithString:s];
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:url];
    request.delegate = self;
    [request startAsynchronous];
}


#pragma mark ASIHTTPRequest代理协议的实现
- (void)requestFailed:(ASIHTTPRequest *)request{
    [self.view makeToast:NSLocalizedString(@"str_networkUnAvailable", @"当前网络不可用,请检查您的网络设置")];
}

- (void)requestFinished:(ASIHTTPRequest *)request{
    
    [self parseResponsenWithData:request.responseData];
}

- (void)parseResponsenWithData:(NSData *)response{
    NSError *error;
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
    NSString *result = [dict objectForKey:@"result"];
    if ([result isEqualToString:@"success"]) {
        if (self.realNameTextFiled.text.length > 0) {
             [[UserDefaultsUtil shareInstance]saveStringConfig:LC_TRUENAME :self.realNameTextFiled.text];
        }
        [self.view makeToast:NSLocalizedString(@"str_modifyUserInformationSuccess",@"修改用户信息成功")];
    }else{
        NSString *err  = [dict objectForKey:@"errCode"];
        switch ([err intValue]) {
            case 1:
                [self.view makeToast:NSLocalizedString(@"str_emptyGUID", @"用户GUID为空")];
                break;
            case 2:
                [self.view makeToast:NSLocalizedString(@"str_userNotFound", @"用户不存在")];
                break;
            case 3:
                [self.view makeToast:NSLocalizedString(@"str_notModifyTheInformation", @"未修改任何信息,至少选择用户名或密码任意一项")];
                break;
            case 4:
                [self.view makeToast:NSLocalizedString(@"str_emptyOldPwd", @"旧密码为空")];
                break;
            case 5:
                [self.view makeToast:NSLocalizedString(@"str_errorOldPwd", @"旧密码错误")];
                break;
                
            case 6:
                [self.view makeToast:NSLocalizedString(@"str_errorSql", @"sql错误")];
                break;
                
            default:
                break;
        }
    }
}

#pragma mark -显示安全密码
-(void)secureBtn:(id)sender{//
    UIButton * secureBtn = (UIButton *)sender;
    if (self.isSecureText) {
        [secureBtn setBackgroundImage:[Utils getImageByDevce:@"logon_icon_08"] forState:UIControlStateNormal];
    }else{
        [secureBtn setBackgroundImage:[Utils getImageByDevce:@"logon_icon_08_pre"] forState:UIControlStateNormal];
    }
    
    self.oldPwdTextFiled.secureTextEntry = self.isSecureText;
     self.newpwdTextFiled.secureTextEntry = self.isSecureText;
    self.isSecureText = !self.isSecureText;
}



@end
